<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\User;
use app\controllers\CommonController;

class MemberController extends CommonController
{
    //登录
    public function actionAuth()
    {
        $this->layout="layout2.php";
        $model=new User();
        if(Yii::$app->request->isPost){
            $post= Yii::$app->request->post();
            if($model->login($post)){
//                var_dump(Yii::$app->session['User']);exit;
                return $this->goBack(Yii::$app->request->referrer);
            }
        }
        return $this->render('auth',['model'=>$model]);
    }
    
    //注册账号，发送电子邮件
    public function actionReg()
    {
        $this->layout="layout2.php";
        $model=new User();
        if(Yii::$app->request->isPost){
            $post= Yii::$app->request->post();
            if($model->regByMail($post)){
                Yii::$app->session->setFlash('info','电子邮件发送成功');
            }
        }
        return $this->render('auth',['model'=>$model]);
    }
    
    //退出
    public function actionLogout()
    {
        Yii::$app->session->removeAll();
//        Yii::$app->session->remove(['User']);
        if(!isset(Yii::$app->session['User']['isLogin'])){
            $this->redirect(['member/auth']);
            Yii::$app->end();
        }
        $this->goBack();;
    }
    
    
}
